
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>滑动 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="layout.html" />
    
    
    <link rel="prev" href="status-ui.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">----安卓 UI----</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="view.html">
            
                <a href="view.html">
            
                    
                    自定义控件和measure
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="canvas-paint.html">
            
                <a href="canvas-paint.html">
            
                    
                    draw和canvas，paint详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="anim.html">
            
                <a href="anim.html">
            
                    
                    动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="notify.html">
            
                <a href="notify.html">
            
                    
                    notify系列库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="loading.html">
            
                <a href="loading.html">
            
                    
                    loading系列库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="status-ui.html">
            
                <a href="status-ui.html">
            
                    
                    StatusUI系列库
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.8" data-path="touch-scroll.html">
            
                <a href="touch-scroll.html">
            
                    
                    滑动
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="layout.html">
            
                <a href="layout.html">
            
                    
                    Layout
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="textview.html">
            
                <a href="textview.html">
            
                    
                    TextView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="drawable.html">
            
                <a href="drawable.html">
            
                    
                    Drawable
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="item-template.html">
            
                <a href="item-template.html">
            
                    
                    列表Adapter模板化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="recyclerview.html">
            
                <a href="recyclerview.html">
            
                    
                    RecyclerView全解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="design.html">
            
                <a href="design.html">
            
                    
                    MeterialDesign详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="component.html">
            
                <a href="component.html">
            
                    
                    AyoComponent基础库--Activity和Fragment
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="systembartint.html">
            
                <a href="systembartint.html">
            
                    
                    SystembarTint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="permission-ask.html">
            
                <a href="permission-ask.html">
            
                    
                    权限控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="keyboard.html">
            
                <a href="keyboard.html">
            
                    
                    小键盘
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="notification.html">
            
                <a href="notification.html">
            
                    
                    Notification
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">----安卓 foundation----</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="mvp.html">
            
                <a href="mvp.html">
            
                    
                    MVP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="rxjava.html">
            
                <a href="rxjava.html">
            
                    
                    RxJava
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="lang.html">
            
                <a href="lang.html">
            
                    
                    常用工具类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="http.html">
            
                <a href="http.html">
            
                    
                    http
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="xml.html">
            
                <a href="xml.html">
            
                    
                    xml解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="json-reporter.html">
            
                <a href="json-reporter.html">
            
                    
                    Json解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="inject.html">
            
                <a href="inject.html">
            
                    
                    ButterKnife
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="thread.html">
            
                <a href="thread.html">
            
                    
                    安卓线程和looper
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="process.html">
            
                <a href="process.html">
            
                    
                    多进程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="eventbus.html">
            
                <a href="eventbus.html">
            
                    
                    EventBus
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="db.html">
            
                <a href="db.html">
            
                    
                    数据库和ContentProvider
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="job.html">
            
                <a href="job.html">
            
                    
                    定时任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="service.html">
            
                <a href="service.html">
            
                    
                    service
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="opt-mem.html">
            
                <a href="opt-mem.html">
            
                    
                    内存优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15" data-path="opt-network.html">
            
                <a href="opt-network.html">
            
                    
                    网络优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.16" data-path="opt-anr.html">
            
                <a href="opt-anr.html">
            
                    
                    anr排查
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.17" data-path="opt-ui.html">
            
                <a href="opt-ui.html">
            
                    
                    UI卡顿优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.18" data-path="opt-launch.html">
            
                <a href="opt-launch.html">
            
                    
                    启动优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.19" data-path="opt-launch.html">
            
                <a href="opt-launch.html">
            
                    
                    混淆
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.20" data-path="hotfix.html">
            
                <a href="hotfix.html">
            
                    
                    热补丁混淆
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.21" data-path="aar.html">
            
                <a href="aar.html">
            
                    
                    aar相关
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.22" data-path="route.html">
            
                <a href="route.html">
            
                    
                    Route路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.23" data-path="modules.html">
            
                <a href="modules.html">
            
                    
                    分模块，组件化，插件化
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">----Gradle----</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="gradle.html">
            
                <a href="gradle.html">
            
                    
                    gradle基本配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="gradle-plugin.html">
            
                <a href="gradle-plugin.html">
            
                    
                    gradle插件开发
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">----工具----</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="repos.html">
            
                <a href="repos.html">
            
                    
                    优秀博客，开源项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="packs.html">
            
                <a href="packs.html">
            
                    
                    自动打包，多渠道打包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="gist.html">
            
                <a href="gist.html">
            
                    
                    代码片段和常见问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="stetho.html">
            
                <a href="stetho.html">
            
                    
                    stetho
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="fabric.html">
            
                <a href="fabric.html">
            
                    
                    fabric
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="app-update.html">
            
                <a href="app-update.html">
            
                    
                    自动升级
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="bugsnags.html">
            
                <a href="bugsnags.html">
            
                    
                    日志和崩溃统计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="mail.html">
            
                <a href="mail.html">
            
                    
                    发邮件辅助接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="socail.html">
            
                <a href="socail.html">
            
                    
                    第三方登录和分享
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.10" data-path="pay-alipay.html">
            
                <a href="pay-alipay.html">
            
                    
                    支付宝支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.11" data-path="pay-wx.html">
            
                <a href="pay-wx.html">
            
                    
                    微信支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.12" data-path="umeng.html">
            
                <a href="umeng.html">
            
                    
                    友盟统计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.13" data-path="push-jpush.html">
            
                <a href="push-jpush.html">
            
                    
                    推送-极光
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.14" data-path="push-xiaomi.html">
            
                <a href="push-xiaomi.html">
            
                    
                    推送-小米
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >滑动</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x6ED1;&#x52A8;">&#x6ED1;&#x52A8;</h1>
<h2 id="4-&#x4EFF;viewpager">4 &#x4EFF;ViewPager</h2>
<p>&#x4EE3;&#x7801;&#x91CC;&#x662F;FakeHorizontalScrollView</p>
<ul>
<li>&#x6280;&#x672F;&#x70B9;&#xFF1A;<ul>
<li>&#x89E3;&#x51B3;&#x6ED1;&#x52A8;&#x51B2;&#x7A81;&#xFF0C;&#x5185;&#x90E8;&#x53EF;&#x4EE5;&#x5D4C;&#x5957;ListView</li>
<li>&#x52A8;&#x4F5C;&#x5B8C;&#x5168;&#x4EFF;ViewPager</li>
<li>&#x4F7F;&#x7528;&#x4E86;Scroller&#x548C;VelocityTracker</li>
<li>&#x5DE6;&#x53F3;&#x53EF;&#x4EE5;over slide&#xFF0C;&#x9732;&#x51FA;FakeHorizontalScrollView&#x7684;&#x80CC;&#x666F;</li>
</ul>
</li>
</ul>
<ul>
<li>&#x5728;&#x8FD9;&#x91CC;&#x8BB0;&#x5F55;&#x4E00;&#x4E0B;SwipeRefresh&#x7684;&#x539F;&#x7406;&#xFF1A;<ul>
<li>&#x4E00;&#x4E2A;SwipeRefreshLayout&#xFF0C;&#x53EA;&#x8981;&#x5B50;&#x63A7;&#x4EF6;&#x4E0D;&#x80FD;&#x518D;&#x5F80;&#x4E0B;&#x6ED1;&#x4E86;&#xFF0C;&#x5C31;&#x6FC0;&#x6D3B;&#x4E0B;&#x62C9;&#x5237;&#x65B0;&#x6548;&#x679C;<ul>
<li>&#x6240;&#x4EE5;&#x9700;&#x8981;&#x7ED9;&#x6BCF;&#x4E00;&#x4E2A;&#x63A7;&#x4EF6;&#x4E00;&#x4E2A;&#x56DE;&#x8C03;&#xFF0C;&#x5224;&#x65AD;&#x80FD;&#x4E0D;&#x80FD;&#x5F80;&#x4E0B;&#x6ED1;&#x4E86;</li>
</ul>
</li>
<li>&#x5F80;&#x4E0A;&#x6ED1;&#x4E5F;&#x662F;&#x4E00;&#x4E2A;&#x9053;&#x7406;</li>
</ul>
</li>
</ul>
<h1 id="view&#x8BE6;&#x89E3;">View&#x8BE6;&#x89E3;</h1>
<ul>
<li>&#x672C;&#x6587;&#x63A2;&#x8BA8;&#x7684;&#x662F;&#xFF1A;<ul>
<li>&#x4E8B;&#x4EF6;&#x62E6;&#x622A;</li>
<li>&#x5E38;&#x89C1;&#x63A7;&#x4EF6;&#x7684;&#x6ED1;&#x52A8;&#x4E8B;&#x4EF6;</li>
<li>&#x6ED1;&#x52A8;&#x76F8;&#x5173;&#x7279;&#x6548;</li>
</ul>
</li>
</ul>
<h2 id="0-&#x5904;&#x7406;&#x6ED1;&#x52A8;">0 &#x5904;&#x7406;&#x6ED1;&#x52A8;</h2>
<p>&#x5904;&#x7406;&#x6ED1;&#x52A8;&#x7684;&#x4E00;&#x822C;&#x4EE3;&#x7801;&#x662F;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">int</span> mLastX = <span class="hljs-number">0</span>;
<span class="hljs-keyword">int</span> mLastY = <span class="hljs-number">0</span>;

<span class="hljs-meta">@Override</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">onTouchEvent</span><span class="hljs-params">(MotionEvent e)</span> </span>{
    <span class="hljs-keyword">boolean</span> consume = <span class="hljs-keyword">false</span>;
    <span class="hljs-keyword">int</span> x = (<span class="hljs-keyword">int</span>)e.getX();
    <span class="hljs-keyword">int</span> y = (<span class="hljs-keyword">int</span>)e.getY();
    <span class="hljs-keyword">if</span>(e.getAction() == MotionEvent.ACTION_DOWN){
        consume = <span class="hljs-keyword">true</span>;
    }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(e.getAction() == MotionEvent.ACTION_MOVE){
        <span class="hljs-keyword">int</span> dx = x - mLastX;
        <span class="hljs-keyword">int</span> dy = y - mLastY;
        consume = <span class="hljs-keyword">true</span>;
        onFingerMove(x, y, dx, dy);
    }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(e.getAction() == MotionEvent.ACTION_UP){
        consume = <span class="hljs-keyword">true</span>;
    }

    mLastX = x;
    mLastY = y;
    <span class="hljs-keyword">return</span> consume;
}


<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onFingerMove</span><span class="hljs-params">(<span class="hljs-keyword">int</span> x, <span class="hljs-keyword">int</span> y, <span class="hljs-keyword">int</span> dx, <span class="hljs-keyword">int</span> dy)</span></span>{}
</code></pre>
<h2 id="1-&#x4E8B;&#x4EF6;&#x4F20;&#x9012;&#x673A;&#x5236;">1 &#x4E8B;&#x4EF6;&#x4F20;&#x9012;&#x673A;&#x5236;</h2>
<p>&#x4F20;&#x9012;&#x8FC7;&#x7A0B;&#xFF1A;Activity--&gt;Window--&gt;ViewGroup&#x94FE;&#xFF08;1&#x5230;n&#x4E2A;&#xFF09;-&gt;View&#xFF08;0&#x6216;1&#x4E2A;&#xFF09;
ViewGroup&#x94FE;&#x81F3;&#x5C11;&#x6709;&#x4E00;&#x4E2A;ViewGroup
&#x6700;&#x540E;&#x4F20;&#x7ED9;&#x7684;View&#xFF0C;&#x53EF;&#x80FD;0&#x4E2A;&#x6216;&#x8005;1&#x4E2A;
&#x5982;&#x679C;&#x6700;&#x5E95;&#x5C42;View&#x7684;onTouchEvent&#x8FD4;&#x56DE;false&#xFF0C;&#x5219;&#x4E8B;&#x4EF6;&#x4F1A;&#x88AB;&#x56DE;&#x4F20;&#x7ED9;&#x7236;&#x5BB9;&#x5668;&#x7684;onTouchEvent&#xFF0C;&#x76F4;&#x5230;&#x56DE;&#x5230;Activity&#x7684;onTouchEvent</p>
<pre><code class="lang-java">&#x4E0B;&#x9762;&#x662F;&#x548C;&#x4E8B;&#x4EF6;&#x5206;&#x53D1;&#x6709;&#x5173;&#x7684;&#x6E90;&#x7801;

<span class="hljs-comment">//Activity#dispatchTouchEvent</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">dispatchTouchEvent</span><span class="hljs-params">(MotionEvent ev)</span></span>{

    <span class="hljs-comment">///&#x8FD9;&#x6BB5;&#x6682;&#x65F6;&#x5FFD;&#x7565;&#xFF0C;&#x4E0D;&#x77E5;&#x9053;&#x5E72;&#x5565;</span>
    <span class="hljs-keyword">if</span>(ev.getAction() == MotionEvent.ACTION_DOWN){
        onUserInteraction();
    }
    <span class="hljs-comment">///&#x4E8B;&#x4EF6;&#x7ED9;Window&#x5206;&#x53D1;&#xFF0C;&#x5982;&#x679C;&#x8FD4;&#x56DE;true&#xFF0C;&#x8868;&#x793A;&#x4E8B;&#x4EF6;&#x5DF2;&#x88AB;&#x5904;&#x7406;</span>
    <span class="hljs-keyword">if</span>(getWindow().superDispatchTouchEvent(ev)){
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">true</span>;
    }
    <span class="hljs-comment">///&#x5982;&#x679C;&#x4E8B;&#x4EF6;&#x6CA1;&#x6709;&#x88AB;&#x5904;&#x7406;&#xFF0C;&#x5219;&#x4EA4;&#x7ED9;Activity&#x7684;onTouchEvent</span>
    <span class="hljs-keyword">return</span> onTouchEvent(ev);
}

<span class="hljs-comment">//PhoneWindow#superDispatchTouchEvent</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">superDispatchTouchEvent</span><span class="hljs-params">(MotionEvent ev)</span></span>{
    <span class="hljs-keyword">return</span> mDecor.superDispatchTouchEvent(ev);
}

<span class="hljs-comment">//DecoreView&#x5176;&#x5B9E;&#x662F;FrameLayout&#xFF0C;&#x6240;&#x4EE5;&#x4E0B;&#x4E00;&#x6B65;&#x5176;&#x5B9E;&#x662F;&#x8FDB;&#x5165;&#x4E86;ViewGroup&#x7684;dispatchTouchEvent</span>
<span class="hljs-comment">//&#x4EE3;&#x7801;&#x592A;&#x957F;&#x4E86;&#xFF0C;&#x9009;&#x51E0;&#x6BB5;&#x91CD;&#x8981;&#x7684;</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">dispatchTouchEvent</span><span class="hljs-params">(MotionEvent ev)</span></span>{

    <span class="hljs-comment">///&#x5904;&#x7406;&#x62E6;&#x622A;&#x903B;&#x8F91;</span>
    <span class="hljs-comment">//&#x5982;&#x679C;&#x662F;down&#x4E8B;&#x4EF6;&#xFF0C;&#x524D;&#x9762;&#x8FD8;&#x6709;&#x6BB5;&#x4EE3;&#x7801;&#xFF0C;&#x53EF;&#x4EE5;&#x4FDD;&#x8BC1;disallowIntercept&#x4E00;&#x5B9A;&#x4E3A;false&#xFF0C;&#x6240;&#x4EE5;down&#x65F6;&#x4E00;&#x5B9A;&#x4F1A;&#x8C03;&#x7528;onInterceptTouchEvent(ev)</span>
    <span class="hljs-comment">//&#x5982;&#x679C;&#x62E6;&#x622A;&#x4E86;down&#xFF0C;&#x5219;mFirstTouchTarget&#x5FC5;&#x4E3A;null&#xFF0C;&#x540E;&#x7EED;move&#x548C;up&#x4E0D;&#x4F1A;&#x518D;&#x8C03;&#x7528;onInterceptTouchEvent(ev)&#xFF0C;&#x76F4;&#x63A5;&#x62E6;&#x622A;</span>
    <span class="hljs-comment">//&#x5982;&#x679C;&#x6CA1;&#x62E6;&#x622A;down</span>
        <span class="hljs-comment">//&#x6709;&#x5B50;&#x63A7;&#x4EF6;&#x5904;&#x7406;&#x4E8B;&#x4EF6;&#xFF08;&#x80FD;&#x627E;&#x5230;&#x5408;&#x9002;&#x5B50;&#x63A7;&#x4EF6;&#xFF0C;&#x4E14;&#x5B50;&#x63A7;&#x4EF6;&#x7684;dispatchTouchEvent&#x8FD4;&#x56DE;true&#xFF09;&#xFF0C;&#x5219;mFirstTouchTarget&#x88AB;&#x8D4B;&#x503C;&#xFF0C;</span>
            <span class="hljs-comment">//&#x540E;&#x7EED;move&#x548C;up&#x4E8B;&#x4EF6;&#x8FD8;&#x4F1A;&#x7EE7;&#x7EED;&#x5C1D;&#x8BD5;&#x62E6;&#x622A;&#xFF0C;&#x4F46;&#x662F;&#x5982;&#x679C;requestDisallowInterceptTouchEvent&#xFF0C;&#x5219;&#x4E0D;&#x8D70;onInterceptTouchEvent&#xFF0C;&#x4E5F;&#x4E0D;&#x4F1A;&#x62E6;&#x622A;</span>
        <span class="hljs-comment">//&#x65E0;&#x5B50;&#x63A7;&#x4EF6;&#x5904;&#x7406;&#x4E8B;&#x4EF6;&#xFF0C;&#x5219;mFirstTouchTarget&#x4E3A;null&#xFF0C;&#x540E;&#x7EED;move&#x548C;up&#x76F4;&#x63A5;&#x62E6;&#x622A;&#xFF0C;&#x4E0D;&#x8D70;onInterceptTouchEvent</span>
    <span class="hljs-comment">//&#x5BF9;&#x4E8E;&#x540E;&#x7EED;move&#x548C;up&#xFF0C;&#x65E0;&#x5B50;&#x63A7;&#x4EF6;&#x5904;&#x7406;&#x4E8B;&#x4EF6;&#xFF0C;&#x76F4;&#x63A5;</span>
    <span class="hljs-comment">// Check for interception.</span>
    <span class="hljs-keyword">final</span> <span class="hljs-keyword">boolean</span> intercepted;
    <span class="hljs-keyword">if</span> (actionMasked == MotionEvent.ACTION_DOWN
            || mFirstTouchTarget != <span class="hljs-keyword">null</span>) {
        <span class="hljs-keyword">final</span> <span class="hljs-keyword">boolean</span> disallowIntercept = (mGroupFlags &amp; FLAG_DISALLOW_INTERCEPT) != <span class="hljs-number">0</span>;
        <span class="hljs-keyword">if</span> (!disallowIntercept) {
            intercepted = onInterceptTouchEvent(ev);
            ev.setAction(action); <span class="hljs-comment">// restore action in case it was changed</span>
        } <span class="hljs-keyword">else</span> {
            intercepted = <span class="hljs-keyword">false</span>;
        }
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-comment">// There are no touch targets and this action is not an initial down</span>
        <span class="hljs-comment">// so this view group continues to intercept touches.</span>
        intercepted = <span class="hljs-keyword">true</span>;
    }

    <span class="hljs-comment">///&#x5982;&#x679C;&#x62E6;&#x622A;&#x4E86;</span>
    <span class="hljs-comment">//&#x4F20;&#x5230;&#x4E86;View#dispatchTouchEvent</span>

    <span class="hljs-comment">///&#x5982;&#x679C;&#x6CA1;&#x62E6;&#x622A;</span>
    <span class="hljs-comment">///&#x5982;&#x679C;&#x5B50;&#x63A7;&#x4EF6;&#x5904;&#x7406;&#x4E86;&#x4E8B;&#x4EF6;&#xFF08;&#x80FD;&#x627E;&#x5230;&#x53EF;&#x4EE5;&#x63A5;&#x6536;&#x4E8B;&#x4EF6;&#x7684;&#x5B50;&#x63A7;&#x4EF6;&#xFF08;&#x6CA1;&#x6709;&#x6B63;&#x5728;&#x8FDB;&#x884C;&#x52A8;&#x753B;&#xFF0C;&#x4E14;&#x88AB;&#x89E6;&#x6478;&#x7684;&#xFF09;&#xFF0C;&#x4E14;dispatchTouchEvent&#x8FD4;&#x56DE;true&#xFF09;&#xFF0C;&#x5219;&#x8D4B;&#x503C;&#x7ED9;mFirstTouchTarget</span>
    <span class="hljs-comment">///&#x5982;&#x679C;&#x662F;ViewGroup&#xFF0C;&#x8C03;&#x7528;&#x4E86;ViewGroup#dispatchEvent&#xFF0C;&#x91CD;&#x590D;&#x4E0A;&#x9762;&#x8FC7;&#x7A0B;</span>
    <span class="hljs-comment">///&#x5982;&#x679C;&#x662F;View&#xFF0C;&#x8C03;&#x7528;&#x4E86;View#dispatchEvent</span>
    <span class="hljs-comment">///&#x5982;&#x679C;&#x6CA1;&#x6709;&#x5B50;&#x63A7;&#x4EF6;&#x5904;&#x7406;&#x4E8B;&#x4EF6;&#xFF0C;&#xFF0C;&#x5219;&#x56DE;&#x5230;Acvitivity#onTouchEvent</span>

}

<span class="hljs-comment">//&#x518D;&#x770B;View#dispatchTouchEvent</span>
<span class="hljs-comment">//mOnTouchListener&#x6709;&#xFF0C;&#x4E14;mOnTouchListener.onTouch&#x8FD4;&#x56DE;true&#xFF0C;&#x5219;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7ED3;&#x675F;</span>
<span class="hljs-comment">//&#x5426;&#x5219;&#xFF0C;&#x8C03;&#x7528;View#onTouchEvent(e)</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">dispatchTouchEvent</span><span class="hljs-params">(MotionEvent event)</span> </span>{
    <span class="hljs-comment">// If the event should be handled by accessibility focus first.</span>
    <span class="hljs-keyword">if</span> (event.isTargetAccessibilityFocus()) {
        <span class="hljs-comment">// We don&apos;t have focus or no virtual descendant has it, do not handle the event.</span>
        <span class="hljs-keyword">if</span> (!isAccessibilityFocusedViewOrHost()) {
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">false</span>;
        }
        <span class="hljs-comment">// We have focus and got the event, then use normal event dispatch.</span>
        event.setTargetAccessibilityFocus(<span class="hljs-keyword">false</span>);
    }

    <span class="hljs-keyword">boolean</span> result = <span class="hljs-keyword">false</span>;

    <span class="hljs-keyword">if</span> (mInputEventConsistencyVerifier != <span class="hljs-keyword">null</span>) {
        mInputEventConsistencyVerifier.onTouchEvent(event, <span class="hljs-number">0</span>);
    }

    <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> actionMasked = event.getActionMasked();
    <span class="hljs-keyword">if</span> (actionMasked == MotionEvent.ACTION_DOWN) {
        <span class="hljs-comment">// Defensive cleanup for new gesture</span>
        stopNestedScroll();
    }

    <span class="hljs-keyword">if</span> (onFilterTouchEventForSecurity(event)) {
        <span class="hljs-keyword">if</span> ((mViewFlags &amp; ENABLED_MASK) == ENABLED &amp;&amp; handleScrollBarDragging(event)) {
            result = <span class="hljs-keyword">true</span>;
        }
        <span class="hljs-comment">//noinspection SimplifiableIfStatement</span>
        ListenerInfo li = mListenerInfo;
        <span class="hljs-keyword">if</span> (li != <span class="hljs-keyword">null</span> &amp;&amp; li.mOnTouchListener != <span class="hljs-keyword">null</span>
                &amp;&amp; (mViewFlags &amp; ENABLED_MASK) == ENABLED
                &amp;&amp; li.mOnTouchListener.onTouch(<span class="hljs-keyword">this</span>, event)) {
            result = <span class="hljs-keyword">true</span>;
        }

        <span class="hljs-keyword">if</span> (!result &amp;&amp; onTouchEvent(event)) {
            result = <span class="hljs-keyword">true</span>;
        }
    }

    <span class="hljs-keyword">if</span> (!result &amp;&amp; mInputEventConsistencyVerifier != <span class="hljs-keyword">null</span>) {
        mInputEventConsistencyVerifier.onUnhandledEvent(event, <span class="hljs-number">0</span>);
    }

    <span class="hljs-comment">// Clean up after nested scrolls if this is the end of a gesture;</span>
    <span class="hljs-comment">// also cancel it if we tried an ACTION_DOWN but we didn&apos;t want the rest</span>
    <span class="hljs-comment">// of the gesture.</span>
    <span class="hljs-keyword">if</span> (actionMasked == MotionEvent.ACTION_UP ||
            actionMasked == MotionEvent.ACTION_CANCEL ||
            (actionMasked == MotionEvent.ACTION_DOWN &amp;&amp; !result)) {
        stopNestedScroll();
    }

    <span class="hljs-keyword">return</span> result;
}

<span class="hljs-comment">///View#onTouchEvent</span>
<span class="hljs-comment">//&#x4F1A;&#x8C03;&#x7528;performClick&#xFF0C;&#x6FC0;&#x6D3B;onClickListner.onClick&#xFF0C;&#x8FD8;&#x4F1A;&#x5904;&#x7406;longClick</span>
</code></pre>
<ul>
<li>&#x51E0;&#x4E2A;&#x70B9;&#x9700;&#x8981;&#x6CE8;&#x610F;&#xFF1A;<ul>
<li>&#x4E00;&#x4E2A;TouchEvent&#x4E8B;&#x4EF6;&#xFF0C;&#x603B;&#x662F;&#x4ECE;&#x5C5E;&#x4E8E;&#x4E00;&#x4E2A;&#x4E8B;&#x4EF6;&#x5E8F;&#x5217;&#xFF0C;&#x8FD9;&#x4E2A;&#x5E8F;&#x5217;&#x4ECE;down&#x5F00;&#x59CB;&#xFF0C;&#x7ECF;&#x8FC7;&#x591A;&#x4E2A;move&#xFF0C;&#x76F4;&#x5230;up&#x7ED3;&#x675F;</li>
<li>&#x67D0;&#x4E2A;View&#x53EA;&#x8981;&#x62E6;&#x622A;&#x4E00;&#x4E2A;&#x4E8B;&#x4EF6;&#xFF0C;&#x5219;&#x6B64;&#x5E8F;&#x5217;&#x90FD;&#x53EA;&#x80FD;&#x5B83;&#x6765;&#x5904;&#x7406;&#xFF0C;onInterceptTouchEvent&#x4E0D;&#x4F1A;&#x518D;&#x88AB;&#x8C03;&#x7528;</li>
<li>&#x6B63;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4E00;&#x4E2A;&#x4E8B;&#x4EF6;&#x5E8F;&#x5217;&#x53EA;&#x80FD;&#x7531;&#x4E00;&#x4E2A;View&#x6765;&#x6D88;&#x8017;&#xFF0C;&#x4F46;&#x7279;&#x6B8A;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4E00;&#x4E2A;View&#x53EF;&#x4EE5;&#x901A;&#x8FC7;onTouchEvent&#x5F3A;&#x884C;&#x628A;&#x4E8B;&#x4EF6;&#x4F20;&#x7ED9;&#x5176;&#x4ED6;View</li>
<li>View&#x4E0D;&#x6D88;&#x8017;ACTION_DOWN&#xFF0C;&#x5373;&#x5728;onTouchEvent&#x8FD4;&#x56DE;&#x4E86;false&#xFF0C;&#x5219;&#x540E;&#x7EED;&#x7684;move&#x548C;up&#x4E0D;&#x518D;&#x7ED9;&#x5B83;&#x4E86;&#xFF0C;&#x800C;&#x662F;&#x4EA4;&#x7ED9;&#x5176;&#x7236;&#x63A7;&#x4EF6;&#x7684;onTouchEvent</li>
<li>View&#x53EA;&#x6D88;&#x8017;ACTION_DOWN&#xFF0C;&#x5176;&#x4ED6;move&#x548C;up&#x90FD;&#x8FD4;&#x56DE;&#x4E86;false&#xFF0C;&#x5219;&#x6B64;&#x4E8B;&#x4EF6;&#x6D88;&#x5931;&#xFF0C;&#x7236;&#x7684;onTouchEvent&#x4E0D;&#x4F1A;&#x88AB;&#x8C03;&#x7528;&#xFF0C;&#x5E76;&#x4E14;&#x6B64;View&#x8FD8;&#x662F;&#x53EF;&#x4EE5;&#x63A5;&#x6536;&#x5230;&#x6240;&#x6709;&#x4E8B;&#x4EF6;&#xFF0C;&#x6700;&#x540E;&#x8FD9;&#x4E9B;&#x6D88;&#x5931;&#x7684;&#x4E8B;&#x4EF6;&#x90FD;&#x4F20;&#x9012;&#x7ED9;&#x4E86;Activity</li>
<li>ViewGroup&#x9ED8;&#x8BA4;onInterceptTouchEvent&#x8FD4;&#x56DE;false&#xFF0C;&#x5373;&#x4E0D;&#x62E6;&#x622A;</li>
<li>View&#x6CA1;&#x6709;onInterceptTouchEvent&#xFF0C;&#x4E8B;&#x4EF6;&#x6765;&#x4E86;&#xFF0C;onTouchEvent&#x80AF;&#x5B9A;&#x4F1A;&#x8C03;&#x7528;</li>
<li>View&#x9ED8;&#x8BA4;onTouchEvent&#x90FD;&#x8FD4;&#x56DE;true&#xFF0C;&#x9664;&#x975E;clickable&#x548C;longClickable&#x90FD;&#x4E3A;false</li>
<li>disable&#x548C;enable&#x5C5E;&#x6027;&#x4E0D;&#x5F71;&#x54CD;onTouchEvent&#x7684;&#x8FD4;&#x56DE;&#xFF0C;&#x4F46;&#x53EF;&#x80FD;&#x5F71;&#x54CD;&#x662F;&#x5426;&#x8C03;&#x7528;clickLisenter</li>
<li>&#x4E00;&#x6B21;onClick&#x4E8B;&#x4EF6;&#xFF0C;&#x5FC5;&#x987B;&#x6536;&#x5230;down&#x548C;up&#x4E4B;&#x540E;&#x624D;&#x4F1A;&#x88AB;&#x6FC0;&#x6D3B;</li>
<li>&#x4E8B;&#x4EF6;&#x4F20;&#x9012;&#x7531;&#x5916;&#x5411;&#x5185;&#xFF0C;&#x7531;&#x7236;&#x5206;&#x53D1;&#x7ED9;&#x5B50;&#xFF0C;&#x4F46;requestDisallowInterceptTouchEvent&#x53EF;&#x4EE5;&#x88AB;&#x5B50;&#x5229;&#x7528;&#x6765;&#x5E72;&#x9884;&#x7236;&#x7684;&#x4E8B;&#x4EF6;&#x5206;&#x53D1;&#xFF0C;&#x4E0D;&#x8FC7;&#x5F71;&#x54CD;&#x4E0D;&#x4E86;ACTION_DOWN&#x4E8B;&#x4EF6;<ul>
<li>&#x8FD9;&#x4E2A;&#x5F97;&#x591A;&#x8BF4;&#x4E24;&#x53E5;&#xFF0C;&#x7236;&#x53EF;&#x4EE5;&#x62E6;&#x622A;ACTION_DOWN&#xFF0C;&#x7406;&#x8BBA;&#x4E0A;&#x6240;&#x6709;&#x540E;&#x7EED;&#x4E8B;&#x4EF6;&#x53EA;&#x80FD;&#x7ED9;&#x7236;&#x4E86;</li>
<li>&#x4F46;&#x5B50;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;requestDisallowInterceptTouchEvent&#x5F97;&#x5230;&#x540E;&#x7EED;&#x7684;move&#x548C;up&#xFF1F;&#x662F;&#x8FD9;&#x4E2A;&#x610F;&#x601D;&#x5417;</li>
</ul>
</li>
<li>&#x5B50;&#x63A7;&#x4EF6;&#x5FC5;&#x987B;&#x63A5;&#x6536;&#x5230;down&#xFF0C;&#x624D;&#x80FD;&#x63A5;&#x6536;&#x540E;&#x7EED;move&#x548C;up<ul>
<li>&#x6240;&#x4EE5;&#x89E3;&#x51B3;&#x6ED1;&#x52A8;&#x51B2;&#x7A81;&#x65F6;&#xFF0C;&#x7236;&#x80AF;&#x5B9A;&#x4E0D;&#x80FD;intercept&#x4E8B;&#x4EF6;down&#xFF0C;&#x4E0D;&#x8FC7;&#x540E;&#x7EED;&#x7684;move&#xFF0C;&#x7236;&#x53EF;&#x4EE5;intercept&#x4E86;</li>
<li>&#x7236;&#x4E5F;&#x53EF;&#x4EE5;intercept&#x4E8B;&#x4EF6;move&#xFF0C;&#x653E;&#x884C;&#x4E8B;&#x4EF6;down&#xFF0C;&#x800C;&#x5B50;&#x53EF;&#x4EE5;&#x5229;&#x7528;requestDisallowInterceptTouchEvent&#x544A;&#x8BC9;&#x7236;&#x7684;dispatchTouchEvent&#x8981;&#x4E0D;&#x8981;&#x53BB;&#x62E6;&#x622A;<ul>
<li>&#x5B50;&#x53CD;&#x6B63;&#x80AF;&#x5B9A;&#x80FD;&#x62FF;&#x5230;down</li>
<li>&#x5BF9;&#x4E8E;move&#xFF0C;&#x5B50;&#x5982;&#x679C;&#x8981;&#xFF0C;&#x5219;parent.requestDisallowInterceptTouchEvent(true)&#xFF0C;&#x7236;&#x5C31;&#x4E0D;&#x4F1A;&#x518D;&#x8D70;intercept&#xFF0C;&#x4E8B;&#x4EF6;&#x90FD;&#x7ED9;&#x4E86;&#x5B50;&#xFF0C;&#x6ED1;&#x52A8;&#x4E5F;&#x5C31;&#x4EA4;&#x7ED9;&#x4E86;&#x5B50;</li>
<li>&#x5B50;&#x5982;&#x679C;&#x4E0D;&#x8981;&#xFF0C;&#x5219;parent.requestDisallowInterceptTouchEvent(false)&#xFF0C;&#x7236;&#x5C31;&#x4F1A;intercept&#x540E;&#x7EED;&#x4E8B;&#x4EF6;&#xFF0C;&#x6ED1;&#x52A8;&#x5C31;&#x4EA4;&#x7ED9;&#x4E86;&#x7236;&#x7684;onTouchEvent&#x6765;&#x5904;&#x7406;</li>
</ul>
</li>
<li>&#x6240;&#x4EE5;&#x65E0;&#x8BBA;&#x600E;&#x4E48;&#x5904;&#x7406;&#x6ED1;&#x52A8;&#x51B2;&#x7A81;&#xFF0C;&#x7236;&#x603B;&#x662F;&#x80FD;&#x5F97;&#x5230;down&#xFF08;interceptTouchEvent&#x91CC;&#xFF09;&#xFF0C;&#x5B50;&#x4E5F;&#x603B;&#x662F;&#x80FD;&#x5F97;&#x5230;down&#x4E8B;&#x4EF6;&#xFF08;onTouchEvent&#x91CC;&#xFF09;<ul>
<li>&#x4F46;&#x662F;&#x7236;&#x5982;&#x679C;&#x9700;&#x8981;&#x5904;&#x7406;&#xFF0C;&#x5219;&#x7236;&#x7684;onTouchEvent&#x53EA;&#x80FD;&#x4ECE;move&#x5F00;&#x59CB;&#x4E86;&#xFF0C;&#x53EA;&#x6709;move-up&#x6D41;</li>
<li>&#x5B50;&#x603B;&#x662F;&#x80FD;&#x5F62;&#x6210;down-move-up&#x6D41;</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="2-&#x6ED1;&#x52A8;&#x51B2;&#x7A81;">2 &#x6ED1;&#x52A8;&#x51B2;&#x7A81;</h2>
<ul>
<li>&#x51E0;&#x79CD;&#x51B2;&#x7A81;&#x573A;&#x666F;&#xFF1A;<ul>
<li>&#x7236;&#x8981;&#x5DE6;&#x53F3;&#x6ED1;&#xFF0C;&#x5B50;&#x8981;&#x4E0A;&#x4E0B;&#x6ED1;&#xFF0C;ViewPager&#x5DF2;&#x7ECF;&#x5904;&#x7406;&#x4E86;&#x8FD9;&#x79CD;&#x51B2;&#x7A81;&#xFF0C;&#x80AF;&#x5B9A;&#x662F;&#x5728;intercept&#x91CC;&#x5904;&#x7406;&#x7684;</li>
<li>&#x7236;&#x8981;&#x5DE6;&#x53F3;&#x6ED1;&#xFF0C;&#x5B50;&#x4E5F;&#x8981;&#x5DE6;&#x53F3;&#x6ED1;&#xFF0C;&#x5982;SwipeBack + ViewPager&#xFF0C;&#x8FD9;&#x4E2A;&#x9700;&#x8981;&#x6839;&#x636E;&#x5177;&#x4F53;&#x573A;&#x666F;&#xFF0C;&#x5982;&#x70B9;&#x51FB;&#x7684;&#x4F4D;&#x7F6E;&#xFF0C;&#x9760;&#x8FB9;&#x7F18;&#xFF0C;&#x5219;&#x6ED1;&#x52A8;&#x7ED9;SwipeBack&#x5904;&#x7406;</li>
</ul>
</li>
</ul>
<p>&#x4E0B;&#x9762;&#x5C31;&#x662F;&#x89E3;&#x51B3;&#x51B2;&#x7A81;&#x5E38;&#x7528;&#x7684;&#x5916;&#x90E8;&#x548C;&#x5185;&#x90E8;&#x62E6;&#x622A;&#x6CD5;&#xFF0C;&#x90FD;&#x662F;&#x60EF;&#x7528;&#x5957;&#x8DEF;&#xFF0C;&#x4F60;&#x53EA;&#x9700;&#x8981;&#x5224;&#x65AD;&#x4E0D;&#x540C;&#x7684;&#x6761;&#x4EF6;&#x5C31;&#x884C;&#xFF0C;&#x5982;&#x70B9;&#x51FB;&#x4F4D;&#x7F6E;&#xFF0C;&#x6ED1;&#x52A8;&#x65B9;&#x5411;</p>
<pre><code class="lang-java"><span class="hljs-comment">///--------------------------------</span>
&#x5916;&#x90E8;&#x62E6;&#x622A;&#x6CD5;&#xFF1A;&#x7236;&#x5904;&#x7406;&#x51B2;&#x7A81;
<span class="hljs-comment">///-------------------------------</span>

<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">onInterceptTouchEvent</span><span class="hljs-params">(MotionEvent e)</span></span>{
    <span class="hljs-keyword">boolean</span> intercepted = <span class="hljs-keyword">false</span>;
    <span class="hljs-keyword">int</span> x = (<span class="hljs-keyword">int</span>)e.getX();
    <span class="hljs-keyword">int</span> y = (<span class="hljs-keyword">int</span>)e.getY();
    <span class="hljs-keyword">if</span>(e.getAction() == MotionEvent.ACTION_DOWN){
        intercepted = <span class="hljs-keyword">false</span>;
    }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(e.getAction() == MotionEvent.ACTION_MOVE){
        <span class="hljs-keyword">if</span>(&#x7236;&#x9700;&#x8981;&#x6ED1;&#x52A8;&#x4E8B;&#x4EF6;){
            intercepted = <span class="hljs-keyword">true</span>;
        }<span class="hljs-keyword">else</span>{
            intercepted = <span class="hljs-keyword">false</span>;
        }
    }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(e.getAction() == MotionEvent.ACTION_UP){
        intercepted = <span class="hljs-keyword">false</span>;
    }

    mLastXIntercept = x;
    mLastYIntercept = y;
    <span class="hljs-keyword">return</span> intercepted;
}


<span class="hljs-comment">///--------------------------------</span>
&#x5185;&#x90E8;&#x62E6;&#x622A;&#x6CD5;&#xFF1A;&#x5B50;&#x5904;&#x7406;&#x51B2;&#x7A81;&#xFF0C;&#x7236;&#x9700;&#x8981;&#x914D;&#x5408;
<span class="hljs-comment">///-------------------------------</span>

<span class="hljs-comment">//&#x5B50;&#xFF1A;&#x6839;&#x636E;&#x6761;&#x4EF6;&#x51B3;&#x5B9A;&#x662F;&#x5426;&#x5141;&#x8BB8;&#x7236;&#x62E6;&#x622A;</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">dispatchTouchEvent</span><span class="hljs-params">(MotionEvent e)</span></span>{
    <span class="hljs-keyword">int</span> x = (<span class="hljs-keyword">int</span>)e.getX();
    <span class="hljs-keyword">int</span> y = (<span class="hljs-keyword">int</span>)e.getY();
    <span class="hljs-keyword">if</span>(e.getAction() == MotionEvent.ACTION_DOWN){
        parent.requestDisallowInterceptTouchEvent(<span class="hljs-keyword">true</span>);
    }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(e.getAction() == MotionEvent.ACTION_MOVE){
        <span class="hljs-keyword">int</span> dx = x - mLastX;
        <span class="hljs-keyword">int</span> dy = y - mLastY;
        <span class="hljs-keyword">if</span>(&#x7236;&#x9700;&#x8981;&#x6ED1;&#x52A8;&#x4E8B;&#x4EF6;){
            parent.requestDisallowInterceptTouchEvent(<span class="hljs-keyword">false</span>);
        }<span class="hljs-keyword">else</span>{
            <span class="hljs-comment">//&#x4E8B;&#x4EF6;&#x5C31;&#x5230;&#x4E86;onTouchEvent</span>
        }
    }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(e.getAction() == MotionEvent.ACTION_UP){
    }
    mLastX = x;
    mLastY = y;
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">super</span>.dispatchTouchEvent(e);
}

<span class="hljs-comment">//&#x7236;&#xFF1A;&#x53EA;&#x8981;&#x5141;&#x8BB8;&#x62E6;&#x622A;&#xFF0C;&#x5219;move&#x548C;up&#x90FD;&#x62E6;&#x622A;</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">onInterceptTouchEvent</span><span class="hljs-params">(MotionEvent e)</span></span>{
    <span class="hljs-keyword">int</span> action = e.getAction();
    <span class="hljs-keyword">if</span>(action == MotionEvent.ACTION_DOWN){
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">false</span>;
    }<span class="hljs-keyword">else</span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">true</span>;
    }
}
</code></pre>
<h2 id="3-&#x600E;&#x4E48;&#x8BA9;&#x63A7;&#x4EF6;&#x6ED1;&#x52A8;">3 &#x600E;&#x4E48;&#x8BA9;&#x63A7;&#x4EF6;&#x6ED1;&#x52A8;</h2>
<p>&#x4E0A;&#x4E00;&#x8282;&#x89E3;&#x51B3;&#x4E86;&#x6ED1;&#x52A8;&#x51B2;&#x7A81;&#xFF0C;&#x6ED1;&#x52A8;&#x6743;&#x9650;&#x6700;&#x7EC8;&#x88AB;&#x67D0;&#x4E00;&#x4E2A;&#x63A7;&#x4EF6;&#x83B7;&#x5F97;</p>
<ul>
<li>&#x8981;&#x70B9;<ul>
<li>&#x6ED1;&#x52A8;&#x7684;&#x51E0;&#x79CD;&#x65B9;&#x5F0F;</li>
<li>&#x5E73;&#x6ED1;&#x6ED1;&#x52A8;</li>
<li>&#x60EF;&#x6027;&#x6ED1;&#x52A8;</li>
<li>DragHelper</li>
<li>over slide&#x6548;&#x679C;</li>
<li>pull to refresh&#x5B9E;&#x73B0;</li>
<li>&#x5E38;&#x89C1;&#x63A7;&#x4EF6;&#x7684;scroll&#x76F8;&#x5173;&#x56DE;&#x8C03;&#x548C;&#x65B9;&#x6CD5;&#xFF0C;&#x8DDF;&#x7740;&#x505A;&#x4E00;&#x4E9B;&#x7279;&#x6548;</li>
</ul>
</li>
</ul>
<h3 id="&#x5173;&#x4E8E;&#x5750;&#x6807;&#x7CFB;">&#x5173;&#x4E8E;&#x5750;&#x6807;&#x7CFB;</h3>
<ul>
<li>&#x8981;&#x4E86;&#x89E3;&#x6ED1;&#x52A8;&#xFF0C; &#x5148;&#x5F97;&#x4E86;&#x89E3;&#x5B89;&#x5353;&#x7684;&#x51E0;&#x4E2A;&#x5750;&#x6807;&#x7CFB;<ul>
<li>&#x5C4F;&#x5E55;&#x5750;&#x6807;&#x7CFB;&#xFF1A;&#x5C4F;&#x5E55;&#x5DE6;&#x4E0A;&#x89D2;&#x4E3A;&#x539F;&#x70B9;<ul>
<li>&#x5411;&#x53F3;&#x4E3A;&#x6B63;</li>
<li>&#x5411;&#x4E0B;&#x4E3A;&#x6B63;</li>
<li>&#x5F97;&#x5230;View&#x7684;&#x5C4F;&#x5E55;&#x5750;&#x6807;&#xFF0C;&#x5373;&#x5DE6;&#x4E0A;&#x89D2;&#x5728;&#x5C4F;&#x5E55;&#x4E0A;&#x7684;&#x4F4D;&#x7F6E;&#xFF1A;getLocationOnScreen(int[] location)</li>
<li>&#x5F97;&#x5230;Touch&#x4E8B;&#x4EF6;&#x7684;&#x5C4F;&#x5E55;&#x5750;&#x6807;&#xFF0C;ev.getRawX(), ev.getRawY()</li>
</ul>
</li>
<li>View&#x5750;&#x6807;&#x7CFB;&#xFF1A;&#x7236;View&#x7684;&#x5DE6;&#x4E0A;&#x89D2;&#x4E3A;&#x539F;&#x70B9;<ul>
<li>&#x5411;&#x53F3;&#x4E3A;&#x6B63;</li>
<li>&#x60F3;&#x4E0B;&#x4E3A;&#x6B63;</li>
<li>&#x5F97;&#x5230;View&#x5728;&#x7236;&#x63A7;&#x4EF6;&#x7684;&#x5750;&#x6807;&#xFF1A;&#x548C;&#x5E03;&#x5C40;&#x8FC7;&#x7A0B;&#x6709;&#x5173;&#xFF0C;getLeft(), getTop()&#xFF0C;getRight(), getBottom()&#xFF0C;&#x90FD;&#x662F;&#x5230;&#x7236;&#x63A7;&#x4EF6;&#x5DE6;&#x8FB9;&#x548C;&#x4E0A;&#x8FB9;&#x7684;&#x8DDD;&#x79BB;</li>
<li>&#x5F97;&#x5230;Touch&#x4E8B;&#x4EF6;&#x5728;View&#x91CC;&#x7684;&#x5750;&#x6807;&#xFF1A;ev.getX(), ev.getY()</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="31-scrollto&#x548C;scrollby&#xFF1A;&#x63A7;&#x5236;view&#x5185;&#x5BB9;">3.1 scrollTo&#x548C;scrollBy&#xFF1A;&#x63A7;&#x5236;View&#x5185;&#x5BB9;</h3>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setScrollX</span><span class="hljs-params">(<span class="hljs-keyword">int</span> value)</span> </span>{
    scrollTo(value, mScrollY);
}

<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setScrollY</span><span class="hljs-params">(<span class="hljs-keyword">int</span> value)</span> </span>{
    scrollTo(mScrollX, value);
}

<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> <span class="hljs-title">getScrollX</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">return</span> mScrollX;
}

<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> <span class="hljs-title">getScrollY</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">return</span> mScrollY;
}

<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">scrollBy</span><span class="hljs-params">(<span class="hljs-keyword">int</span> x, <span class="hljs-keyword">int</span> y)</span> </span>{
    scrollTo(mScrollX + x, mScrollY + y);
}

<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">scrollTo</span><span class="hljs-params">(<span class="hljs-keyword">int</span> x, <span class="hljs-keyword">int</span> y)</span> </span>{
    <span class="hljs-keyword">if</span> (mScrollX != x || mScrollY != y) {
        <span class="hljs-keyword">int</span> oldX = mScrollX;
        <span class="hljs-keyword">int</span> oldY = mScrollY;
        mScrollX = x;
        mScrollY = y;
        invalidateParentCaches();
        onScrollChanged(mScrollX, mScrollY, oldX, oldY);
        <span class="hljs-keyword">if</span> (!awakenScrollBars()) {
            postInvalidateOnAnimation();
        }
    }
}
</code></pre>
<ul>
<li><p>&#x9996;&#x5148;&#x8981;&#x660E;&#x767D;mScrollX&#x548C;mScrollY&#xFF1A;</p>
<ul>
<li>mScrollX = View&#x5DE6;&#x8FB9;&#x7F18; - View&#x5185;&#x5BB9;&#x5DE6;&#x8FB9;&#x7F18;         &#x6C34;&#x5E73;&#x65B9;&#x5411;&#x8DDD;&#x79BB;</li>
<li>mScrollY = View&#x4E0A;&#x8FB9;&#x7F18; - View&#x5185;&#x5BB9;&#x4E0A;&#x8FB9;&#x7F18;         &#x5782;&#x76F4;&#x65B9;&#x5411;&#x8DDD;&#x79BB;</li>
<li>&#x5185;&#x5BB9;&#x8FB9;&#x7F18;&#x5728;View&#x8FB9;&#x7F18;&#x7684;&#x5DE6;&#x8FB9;&#x65F6;&#xFF0C;mScrollX &gt; 0</li>
<li>&#x5185;&#x5BB9;&#x8FB9;&#x7F18;&#x5728;View&#x8FB9;&#x7F18;&#x7684;&#x4E0A;&#x8FB9;&#x65F6;&#xFF0C;mScrollY &gt; 0</li>
<li>scrollTo(-x, -y)&#xFF0C;&#x79FB;&#x52A8;&#x65B9;&#x5411;&#x53D6;&#x51B3;&#x4E8E;&#x5F53;&#x524D;scroll&#xFF0C;&#x4F46;&#x79FB;&#x52A8;&#x540E;&#x7684;&#x5185;&#x5BB9;&#x80AF;&#x5B9A;&#x4F4D;&#x4E8E;View&#x7684;&#x5DE6;&#x8FB9;&#x548C;&#x4E0A;&#x8FB9;</li>
<li>scrollBy(-dx, -dy)&#xFF0C;&#x80AF;&#x5B9A;&#x662F;&#x5411;&#x5DE6;&#xFF0C;&#x5411;&#x4E0A;scroll</li>
<li>&#x624B;&#x6307;&#x5934;&#x5F80;&#x53F3;&#x6ED1;&#x52A8;&#xFF0C;&#x4ECE;x&#x5230;x1&#xFF0C;&#x6ED1;&#x52A8;&#x8DDD;&#x79BB;&#x662F;dx = x1 - x&#xFF0C;dx &gt; 0&#xFF0C;&#x800C;View&#x5185;&#x5BB9;&#x5E94;&#x8BE5;&#x5F80;&#x53F3;&#x8D70;dx</li>
<li>&#x624B;&#x6307;&#x5934;&#x5F80;&#x4E0B;&#x6ED1;&#x52A8;&#xFF0C;&#x4ECE;y&#x5230;y1&#xFF0C;&#x6ED1;&#x52A8;&#x8DDD;&#x79BB;&#x662F;dy = y1 - y&#xFF0C;dy &gt; 0&#xFF0C;&#x800C;View&#x5185;&#x5BB9;&#x5E94;&#x8BE5;&#x5F80;&#x4E0B;&#x8D70;dy</li>
</ul>
</li>
<li><p>View&#x7684;&#x8FB9;&#x7F18;&#xFF1A;</p>
<ul>
<li>&#x5C31;&#x662F;View&#x7684;&#x4F4D;&#x7F6E;&#xFF0C;&#x4E0A;&#x4E0B;&#x5DE6;&#x53F3;&#x56DB;&#x4E2A;&#x9876;&#x70B9;&#x51B3;&#x5B9A;&#x4E86;View&#x7684;&#x8FB9;&#x7F18;</li>
</ul>
</li>
<li><p>View&#x7684;&#x5185;&#x5BB9;&#xFF1A;</p>
<ul>
<li>&#x53EF;&#x4EE5;&#x8BA4;&#x4E3A;&#x662F;View&#x6240;&#x6709;&#x7684;&#x5B50;&#x63A7;&#x4EF6;&#x5C31;&#x662F;View&#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x5B50;&#x63A7;&#x4EF6;&#x663E;&#x793A;&#x6210;&#x7684;&#x90A3;&#x526F;&#x753B;</li>
<li>&#x6240;&#x4EE5;scroll&#x53EF;&#x80FD;&#x4F1A;&#x663E;&#x793A;&#x51FA;View&#x672C;&#x8EAB;&#x7684;&#x80CC;&#x666F;</li>
</ul>
</li>
<li><p>&#x6240;&#x4EE5;&#xFF1A;</p>
<ul>
<li>scroll&#x5E76;&#x4E0D;&#x4F1A;&#x79FB;&#x52A8;View&#x672C;&#x8EAB;&#x7684;&#x4F4D;&#x7F6E;</li>
</ul>
</li>
</ul>
<h3 id="32-scrollto&#x548C;scrollby&#x7684;&#x5E73;&#x6ED1;&#x6ED1;&#x52A8;&#xFF1A;scroller">3.2 scrollTo&#x548C;scrollBy&#x7684;&#x5E73;&#x6ED1;&#x6ED1;&#x52A8;&#xFF1A;Scroller</h3>
<p>scrollTo&#x548C;scrollBy&#x90FD;&#x662F;&#x77AC;&#x95F4;&#x6ED1;&#x52A8;&#xFF0C;&#x5982;&#x679C;&#x8981;&#x5B9E;&#x73B0;smoothScroll&#xFF0C;&#x5C31;&#x4F1A;&#x7528;&#x5230;Scroller
&#x5F53;&#x7136;&#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x81EA;&#x5DF1;&#x5199;&#xFF0C;&#x4F46;&#x5199;&#x51FA;&#x6765;&#x4E5F;&#x5C31;&#x662F;&#x4E2A;&#x7B80;&#x964B;&#x7248;&#x7684;Scroller</p>
<p>Scroller&#x6709;&#x56FA;&#x5B9A;&#x7684;&#x4F7F;&#x7528;&#x5957;&#x8DEF;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">private</span> Scroller mScroller;

mScroller = <span class="hljs-keyword">new</span> Scroller(getContext());

<span class="hljs-comment">//&#x5728;ACTION_MOVE&#x65F6;&#xFF0C;&#x4E0B;&#x9762;&#x4EE3;&#x7801;&#x80FD;&#x4F18;&#x5316;&#x6ED1;&#x52A8;&#x6548;&#x679C;&#xFF0C;&#x6CE8;&#x610F;&#xFF0C;&#x8DDF;&#x7740;move&#x4E8B;&#x4EF6;scroll&#x65F6;&#xFF0C;&#x672C;&#x8EAB;&#x5C31;&#x662F;&#x5E73;&#x6ED1;&#x7684;&#x6ED1;&#x52A8;&#xFF0C;&#x4E0D;&#x9700;&#x8981;Scroller&#x53C2;&#x4E0E;</span>
<span class="hljs-keyword">if</span>(!mScroller.isFinished()){
    mScroller.abortAnimation();
}

<span class="hljs-comment">//&#x5728;ACTION_UP&#x65F6;&#xFF0C;&#x6216;&#x8005;&#x5176;&#x4ED6;&#x573A;&#x666F;&#x4E0B;&#xFF0C;&#x9700;&#x8981;&#x518D;&#x6ED1;&#x52A8;&#x4E00;&#x7AEF;&#x8DDD;&#x79BB;&#xFF0C;&#x8C03;&#x7528;&#x65B9;&#x6CD5;&#xFF1A;</span>
<span class="hljs-comment">//startX&#xFF1A;&#x5DE6;&#x8FB9;&#x8D77;&#x59CB;&#x4F4D;&#x7F6E;&#xFF0C;&#x4F1A;&#x76F4;&#x63A5;&#x5B9A;&#x4F4D;&#x5230;&#x8FD9;&#x4E2A;&#x4F4D;&#x7F6E;&#xFF0C;&#x518D;&#x5F00;&#x59CB;</span>
<span class="hljs-comment">//startY&#xFF1A;&#x4E0A;&#x8FB9;&#x8D77;&#x59CB;&#x4F4D;&#x7F6E;&#xFF0C;&#x4F1A;&#x76F4;&#x63A5;&#x5B9A;&#x4F4D;&#x5230;&#x8FD9;&#x4E2A;&#x4F4D;&#x7F6E;&#xFF0C;&#x518D;&#x5F00;&#x59CB;</span>
<span class="hljs-comment">//dx&#xFF0C;dy&#xFF1A;&#x6ED1;&#x52A8;&#x7684;&#x8DDD;&#x79BB;&#xFF0C;&#x8D1F;&#x503C;&#xFF0C;&#x5F80;&#x5DE6;&#x548C;&#x4E0A;&#xFF0C;&#x6B63;&#x503C;&#xFF0C;&#x5F80;&#x53F3;&#x548C;&#x4E0B;</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">startScroll</span><span class="hljs-params">(<span class="hljs-keyword">int</span> startX, <span class="hljs-keyword">int</span> startY, <span class="hljs-keyword">int</span> dx, <span class="hljs-keyword">int</span> dy)</span> </span>{
    startScroll(startX, startY, dx, dy, DEFAULT_DURATION);
}

&#x4E00;&#x822C;&#x8FD9;&#x4E48;&#x8C03;&#x7528;&#xFF1A;
mScroller.startScroll(getScrollX(), getScrollY(), dx, dy);
postInvalidate();   <span class="hljs-comment">///&#x8C03;&#x7528;&#x8FD9;&#x53E5;&#x4E4B;&#x540E;&#xFF0C;&#x4F1A;&#x8D70;&#x5230;computeScroll()</span>

<span class="hljs-meta">@Override</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">computeScroll</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">super</span>.computeScroll();
    <span class="hljs-keyword">if</span>(mScroller.computeScrollOffset()){
        scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
        postInvalidate();
    }
}

&#x6548;&#x679C;&#xFF1A;
Scroller&#x4F1A;&#x5728;&#x6307;&#x5B9A;&#x65F6;&#x95F4;&#x5185;&#xFF08;&#x9ED8;&#x8BA4;<span class="hljs-number">250</span>ms&#xFF09;&#xFF0C;&#x7ED9;&#x4F60;&#x63D2;&#x503C;&#x4E00;&#x7CFB;&#x5217;&#x5E73;&#x6ED1;&#x7684;&#x503C;&#xFF0C;&#x5B8C;&#x6210;&#x5E73;&#x6ED1;&#x6ED1;&#x52A8;

&#x4F60;&#x80AF;&#x5B9A;&#x6709;&#x7591;&#x95EE;&#xFF0C;&#x5982;&#x679C;&#x6709;&#x63D2;&#x503C;&#x5668;&#xFF0C;&#x4E0D;&#x5C31;&#x66F4;&#x597D;&#x4E86;&#x5417;&#xFF0C;&#x786E;&#x5B9E;&#x6709;&#xFF1A;
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Scroller</span><span class="hljs-params">(Context context, Interpolator interpolator, <span class="hljs-keyword">boolean</span> flywheel)</span>

&#x9ED8;&#x8BA4;&#x7684;&#x63D2;&#x503C;&#x5668;&#x662F;&#x8FD9;&#x4E2A;&#xFF1A;
<span class="hljs-keyword">static</span> class ViscousFluidInterpolator implements Interpolator </span>{
    <span class="hljs-comment">/** Controls the viscous fluid effect (how much of it). */</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">float</span> VISCOUS_FLUID_SCALE = <span class="hljs-number">8.0f</span>;

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">float</span> VISCOUS_FLUID_NORMALIZE;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">float</span> VISCOUS_FLUID_OFFSET;

    <span class="hljs-keyword">static</span> {

        <span class="hljs-comment">// must be set to 1.0 (used in viscousFluid())</span>
        VISCOUS_FLUID_NORMALIZE = <span class="hljs-number">1.0f</span> / viscousFluid(<span class="hljs-number">1.0f</span>);
        <span class="hljs-comment">// account for very small floating-point error</span>
        VISCOUS_FLUID_OFFSET = <span class="hljs-number">1.0f</span> - VISCOUS_FLUID_NORMALIZE * viscousFluid(<span class="hljs-number">1.0f</span>);
    }

    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">float</span> <span class="hljs-title">viscousFluid</span><span class="hljs-params">(<span class="hljs-keyword">float</span> x)</span> </span>{
        x *= VISCOUS_FLUID_SCALE;
        <span class="hljs-keyword">if</span> (x &lt; <span class="hljs-number">1.0f</span>) {
            x -= (<span class="hljs-number">1.0f</span> - (<span class="hljs-keyword">float</span>)Math.exp(-x));
        } <span class="hljs-keyword">else</span> {
            <span class="hljs-keyword">float</span> start = <span class="hljs-number">0.36787944117f</span>;   <span class="hljs-comment">// 1/e == exp(-1)</span>
            x = <span class="hljs-number">1.0f</span> - (<span class="hljs-keyword">float</span>)Math.exp(<span class="hljs-number">1.0f</span> - x);
            x = start + x * (<span class="hljs-number">1.0f</span> - start);
        }
        <span class="hljs-keyword">return</span> x;
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">float</span> <span class="hljs-title">getInterpolation</span><span class="hljs-params">(<span class="hljs-keyword">float</span> input)</span> </span>{
        <span class="hljs-keyword">final</span> <span class="hljs-keyword">float</span> interpolated = VISCOUS_FLUID_NORMALIZE * viscousFluid(input);
        <span class="hljs-keyword">if</span> (interpolated &gt; <span class="hljs-number">0</span>) {
            <span class="hljs-keyword">return</span> interpolated + VISCOUS_FLUID_OFFSET;
        }
        <span class="hljs-keyword">return</span> interpolated;
    }
}
</code></pre>
<h3 id="33-&#x5176;&#x4ED6;&#x5B9E;&#x73B0;&#x6ED1;&#x52A8;&#x7684;&#x65B9;&#x6CD5;&#xFF1A;">3.3 &#x5176;&#x4ED6;&#x5B9E;&#x73B0;&#x6ED1;&#x52A8;&#x7684;&#x65B9;&#x6CD5;&#xFF1A;</h3>
<ul>
<li>&#x8FD9;&#x91CC;&#x8BF4;&#x7684;&#x662F;&#x63A7;&#x5236;&#x771F;&#x5B9E;View&#x7684;&#x4F4D;&#x7F6E;&#xFF0C;&#x4E0D;&#x662F;View&#x5F71;&#x50CF;&#xFF0C;&#x4E5F;&#x4E0D;&#x662F;View&#x5185;&#x5BB9;<ul>
<li>layout(left, top, right, bottom)&#xFF1A;&#x6B64;&#x65B9;&#x6CD5;&#x8C03;&#x7528;&#x540E;&#xFF0C;&#x4F1A;&#x91CD;&#x65B0;&#x7ED8;&#x5236;View</li>
<li>MarginLayoutParam&#x63A7;&#x5236;margin&#x6765;&#x5B9E;&#x73B0;&#x6ED1;&#x52A8;</li>
<li>offsetLeftAndRight(dx)&#x548C;offsetTopAndBottom(dy)&#xFF1A;&#x8FD9;&#x4E2A;&#x633A;&#x65B0;&#x9C9C;</li>
</ul>
</li>
</ul>
<h3 id="34-&#x4F7F;&#x7528;&#x52A8;&#x753B;&#x6765;&#x6ED1;&#x52A8;&#xFF1A;-&#x63A7;&#x5236;view&#x5F71;&#x50CF;">3.4 &#x4F7F;&#x7528;&#x52A8;&#x753B;&#x6765;&#x6ED1;&#x52A8;&#xFF1A; &#x63A7;&#x5236;View&#x5F71;&#x50CF;</h3>
<ul>
<li>&#x52A8;&#x753B;<ul>
<li>&#x4F7F;&#x7528;&#x8865;&#x95F4;&#x52A8;&#x753B;&#xFF0C;&#x64CD;&#x4F5C;&#x7684;&#x90FD;&#x662F;View&#x7684;&#x5F71;&#x50CF;&#xFF0C;&#x539F;View&#x8FD8;&#x5728;&#x539F;&#x6765;&#x7684;&#x4F4D;&#x7F6E;</li>
<li>&#x6216;&#x8005;&#x5C5E;&#x6027;&#x52A8;&#x753B;&#x63A7;&#x5236;translation&#x5C5E;&#x6027;&#xFF0C;&#x64CD;&#x4F5C;&#x7684;&#x90FD;&#x662F;View&#x7684;&#x5F71;&#x50CF;&#xFF0C;&#x539F;View&#x8FD8;&#x5728;&#x539F;&#x6765;&#x7684;&#x4F4D;&#x7F6E;</li>
<li>&#x4F7F;&#x7528;&#x5C5E;&#x6027;&#x52A8;&#x753B;&#x53EF;&#x4EE5;&#x81EA;&#x5DF1;&#x63A7;&#x5236;3.3&#x4E2D;&#x63D0;&#x5230;&#x7684;&#x6ED1;&#x52A8;&#x63A5;&#x53E3;&#xFF0C;&#x6765;&#x63A7;&#x5236;&#x771F;&#x5B9E;View&#x4F4D;&#x7F6E;</li>
</ul>
</li>
</ul>
<h3 id="35-velocitytracker">3.5 VelocityTracker</h3>
<pre><code class="lang-java"><span class="hljs-keyword">private</span> VelocityTracker mVelocityTracker;

mVelocityTracker = VelocityTracker.obtain();

<span class="hljs-meta">@Override</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">onTouchEvent</span><span class="hljs-params">(MotionEvent event)</span> </span>{
    mVelocityTracker.addMovement(event);
    <span class="hljs-keyword">if</span>(event.getAction() == MotionEvent.ACTION_UP){
        <span class="hljs-keyword">int</span> scrollX = getScrollX();
        <span class="hljs-keyword">int</span> scrollToChildIndex = scrollX / mChildWidth;
        mVelocityTracker.computeCurrentVelocity(<span class="hljs-number">1000</span>);
        <span class="hljs-keyword">float</span> xVelocity = mVelocityTracker.getXVelocity();
        <span class="hljs-keyword">if</span>(Math.abs(xVelocity) &gt;= <span class="hljs-number">50</span>){
                <span class="hljs-comment">///&#x6ED1;&#x52A8;&#x901F;&#x5EA6;&#x5927;&#x4E8E;50&#x65F6;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x5F80;&#x53F3;&#x6ED1;&#xFF0C;&#x901F;&#x5EA6;&#x5927;&#x4E8E;0&#xFF0C;&#x5F80;&#x524D;&#x7FFB;&#xFF1B; &#x5982;&#x679C;&#x662F;&#x5F80;&#x5DE6;&#x6ED1;&#xFF0C;&#x901F;&#x5EA6;&#x5C0F;&#x4E8E;0&#xFF0C; &#x5F80;&#x540E;&#x7FFB;</span>
                mChildIndex = xVelocity &gt; <span class="hljs-number">0</span> ? mChildIndex - <span class="hljs-number">1</span> : mChildIndex + <span class="hljs-number">1</span>;
            }<span class="hljs-keyword">else</span>{
                <span class="hljs-comment">///&#x6ED1;&#x52A8;&#x901F;&#x5EA6;&#x5C0F;&#x4E8E;50&#x65F6;&#xFF0C;&#x6839;&#x636E;&#x5F53;&#x524D;scroll&#x7684;&#x8DDD;&#x79BB;&#xFF0C;&#x5224;&#x65AD;&#x662F;&#x7FFB;&#x56DE;&#x53BB;&#xFF0C;&#x8FD8;&#x662F;&#x5F80;&#x540E;&#x7FFB;&#x4E00;&#x9875;&#xFF0C;&#x603B;&#x4E4B;&#x6700;&#x540E;&#x80AF;&#x5B9A;&#x662F;&#x505C;&#x5728;&#x4E00;&#x9875;&#x4E0A;</span>
                mChildIndex = (scrollX + mChildWidth / <span class="hljs-number">2</span>) / mChildWidth;
            }
         }
    }
}
</code></pre>
<h3 id="36-viewdraghelper">3.6 ViewDragHelper</h3>
<p>Google&#x7684;support&#x4E3A;&#x6211;&#x4EEC;&#x63D0;&#x4F9B;&#x4E86;DrawerLayout&#x548C;SlidingPanelLayout&#x4E24;&#x4E2A;&#x5E03;&#x5C40;&#xFF0C;
&#x5728;&#x8FD9;&#x4E24;&#x4E2A;&#x5E03;&#x5C40;&#x80CC;&#x540E;&#xFF0C;&#x5C31;&#x662F;ViewDragHelper&#xFF0C;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x7C7B;&#xFF0C;&#x57FA;&#x672C;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x6240;&#x6709;&#x6ED1;&#x52A8;&#x548C;&#x62D6;&#x653E;&#x7684;&#x6548;&#x679C;</p>
<p>&#x4E0B;&#x9762;&#x4EE3;&#x7801;&#x4E8B;&#x5148;&#x7684;&#x6548;&#x679C;&#x662F;&#x4E00;&#x4E2A;ViewGroup&#x91CC;&#x4E24;&#x4E2A;&#x63A7;&#x4EF6;&#x90FD;&#x53EF;&#x4EE5;&#x62D6;&#x52A8;&#xFF0C;&#x800C;&#x4E14;&#x677E;&#x624B;&#x540E;&#x4F1A;&#x56DE;&#x5F39;&#x5230;&#x4E00;&#x4E2A;&#x56FA;&#x5B9A;&#x7684;&#x4F4D;&#x7F6E;</p>
<p>&#x8FD9;&#x91CC;&#x5176;&#x5B9E;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;ViewDragHelper&#x4F7F;&#x7528;&#x7684;&#x6A21;&#x677F;&#xFF0C;&#x5B9E;&#x9645;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x53EF;&#x80FD;&#x4E00;&#x822C;&#x4E0D;&#x4F1A;&#x76F4;&#x63A5;&#x7EE7;&#x627F;ViewGroup&#xFF0C;&#x800C;&#x662F;&#x7EE7;&#x627F;FrameLayout&#x4E4B;&#x7C7B;&#x7684;</p>
<p>&#x5177;&#x4F53;&#x7528;&#x6CD5;&#x53EF;&#x4EE5;&#x53C2;&#x8003;SwipeBackLayout&#x7684;&#x5B9E;&#x73B0;&#xFF0C;&#x662F;&#x4E2A;&#x597D;&#x4F8B;&#x5B50;</p>
<pre><code class="lang-java">
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ViewDragHelperDemoView2</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FrameLayout</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">ViewDragHelperDemoView2</span><span class="hljs-params">(Context context)</span> </span>{
        <span class="hljs-keyword">super</span>(context);
        init();
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">ViewDragHelperDemoView2</span><span class="hljs-params">(Context context, AttributeSet attrs)</span> </span>{
        <span class="hljs-keyword">super</span>(context, attrs);
        init();
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">ViewDragHelperDemoView2</span><span class="hljs-params">(Context context, AttributeSet attrs, <span class="hljs-keyword">int</span> defStyleAttr)</span> </span>{
        <span class="hljs-keyword">super</span>(context, attrs, defStyleAttr);
        init();
    }

    <span class="hljs-meta">@RequiresApi</span>(api = Build.VERSION_CODES.LOLLIPOP)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">ViewDragHelperDemoView2</span><span class="hljs-params">(Context context, AttributeSet attrs, <span class="hljs-keyword">int</span> defStyleAttr, <span class="hljs-keyword">int</span> defStyleRes)</span> </span>{
        <span class="hljs-keyword">super</span>(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    ViewDragHelper mViewDragHelper;

    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">init</span><span class="hljs-params">()</span></span>{
        mViewDragHelper = ViewDragHelper.create(<span class="hljs-keyword">this</span>, callback);
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">onInterceptHoverEvent</span><span class="hljs-params">(MotionEvent event)</span> </span>{
        <span class="hljs-keyword">return</span> mViewDragHelper.shouldInterceptTouchEvent(event);
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">onTouchEvent</span><span class="hljs-params">(MotionEvent event)</span> </span>{
        mViewDragHelper.processTouchEvent(event);
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">true</span>;
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">computeScroll</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-comment">//&#x8FD9;&#x91CC;&#x662F;&#x4E00;&#x4E2A;&#x5E38;&#x7528;&#x6A21;&#x677F;&#xFF0C;ViewDragHelper&#x5185;&#x90E8;&#x4E5F;&#x662F;&#x901A;&#x8FC7;Scroller&#x5B9E;&#x73B0;&#x5E73;&#x6ED1;&#x6ED1;&#x52A8;</span>
        <span class="hljs-keyword">if</span>(mViewDragHelper.continueSettling(<span class="hljs-keyword">true</span>)){
            ViewCompat.postInvalidateOnAnimation(<span class="hljs-keyword">this</span>);
        }
    }

    <span class="hljs-keyword">private</span> ViewDragHelper.Callback callback = <span class="hljs-keyword">new</span> ViewDragHelper.Callback(){

        <span class="hljs-comment">/**
         * child&#x662F;&#x88AB;&#x89E6;&#x6478;&#x7684;View&#xFF0C;&#x8FD9;&#x91CC;&#x4F60;&#x6765;&#x544A;&#x8BC9;helper&#x8FD9;&#x4E2A;child&#x662F;&#x5426;&#x53EF;&#x4EE5;&#x5F00;&#x59CB;&#x68C0;&#x6D4B;&#x6ED1;&#x52A8;
         *
         * &#x4E00;&#x822C;&#x65B9;&#x6CD5;&#x662F;&#x4E8B;&#x5148;&#x5B9A;&#x597D;&#x51E0;&#x4E2A;id&#xFF0C;&#x6839;&#x636E;id&#x5224;&#x65AD;&#x662F;&#x5426;&#x53EF;&#x4EE5;&#x6ED1;&#x52A8;&#xFF0C;&#x5982;DrawerLayout
         int headerId= getResources().getIdentifier(&quot;sticky_header&quot;, &quot;id&quot;, getContext().getPackageName());
         int contentId = getResources().getIdentifier(&quot;sticky_content&quot;, &quot;id&quot;, getContext().getPackageName());
         &#x8868;&#x793A;header&#x7684;id&#x5FC5;&#x987B;&#x662F;R.id.sticky_header&#xFF0C; &#x5185;&#x5BB9;&#x5E03;&#x5C40;&#x7684;id&#x5FC5;&#x987B;&#x662F;R.id.sticky_content

         * <span class="hljs-doctag">@return</span>
         */</span>
        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">tryCaptureView</span><span class="hljs-params">(View child, <span class="hljs-keyword">int</span> pointerId)</span> </span>{
            <span class="hljs-comment">///&#x5982;&#x679C;&#x8FD9;&#x4E2A;ViewGroup&#x6709;&#x4E24;&#x4E2A;&#x5B50;&#x63A7;&#x4EF6;&#xFF0C;menuView&#x548C;contentView&#xFF0C;&#x5219;&#x8FD4;&#x56DE;child == contentView&#x610F;&#x601D;&#x5C31;&#x662F;&#x53EA;&#x6709;contentView&#x80FD;&#x62D6;&#x52A8;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">true</span>;
        }

        <span class="hljs-comment">/**
         * &#x8FD4;&#x56DE;&#x503C;&#x8868;&#x793A;The new clamped position for left&#xFF0C;&#x8FD4;&#x56DE;0&#x8868;&#x793A;&#x4E0D;&#x53D1;&#x751F;&#x6ED1;&#x52A8;
         * <span class="hljs-doctag">@param</span> child Child view being dragged
         * <span class="hljs-doctag">@param</span> left  &#x6C34;&#x5E73;&#x65B9;&#x5411;&#x4E0A;child&#x79FB;&#x52A8;&#x7684;&#x8DDD;&#x79BB;
         * <span class="hljs-doctag">@param</span> dx    &#x548C;&#x524D;&#x4E00;&#x6B21;&#x76F8;&#x6BD4;&#x7684;&#x589E;&#x91CF;
         * <span class="hljs-doctag">@return</span>   &#x4E00;&#x822C;&#x53EA;&#x9700;&#x8981;&#x8FD4;&#x56DE;left&#xFF0C;&#x4F46;&#x5982;&#x679C;&#x9700;&#x8981;&#x66F4;&#x7CBE;&#x786E;&#x7684;&#x8BA1;&#x7B97;padding&#x7B49;&#x5C5E;&#x6027;&#xFF0C;&#x5219;&#x9700;&#x8981;&#x505A;&#x4E00;&#x4E9B;&#x5904;&#x7406;
         */</span>
        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">clampViewPositionHorizontal</span><span class="hljs-params">(View child, <span class="hljs-keyword">int</span> left, <span class="hljs-keyword">int</span> dx)</span> </span>{
            <span class="hljs-keyword">return</span> left;
        }

        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">clampViewPositionVertical</span><span class="hljs-params">(View child, <span class="hljs-keyword">int</span> top, <span class="hljs-keyword">int</span> dy)</span> </span>{
            <span class="hljs-keyword">return</span> top;
        }

        <span class="hljs-comment">//&#x624B;&#x677E;&#x5F00;</span>
        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onViewReleased</span><span class="hljs-params">(View releasedChild, <span class="hljs-keyword">float</span> xvel, <span class="hljs-keyword">float</span> yvel)</span> </span>{
            <span class="hljs-keyword">super</span>.onViewReleased(releasedChild, xvel, yvel);
            Toaster.toastShort(<span class="hljs-string">&quot;&#x624B;&#x6307;&#x677E;&#x5F00;&#x4E86;&quot;</span>);
            mViewDragHelper.smoothSlideViewTo(releasedChild, <span class="hljs-number">300</span>, <span class="hljs-number">500</span>);
            ViewCompat.postInvalidateOnAnimation(ViewDragHelperDemoView2.<span class="hljs-keyword">this</span>);

        }


        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onViewCaptured</span><span class="hljs-params">(View capturedChild, <span class="hljs-keyword">int</span> activePointerId)</span> </span>{
            <span class="hljs-comment">///&#x7528;&#x6237;&#x89E6;&#x6478;&#x5230;View&#x540E;&#x56DE;&#x8C03;</span>
            <span class="hljs-keyword">super</span>.onViewCaptured(capturedChild, activePointerId);
        }

        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onViewDragStateChanged</span><span class="hljs-params">(<span class="hljs-keyword">int</span> state)</span> </span>{
            <span class="hljs-comment">//&#x5728;&#x62D6;&#x66F3;&#x65F6;&#x56DE;&#x8C03;&#xFF0C;&#x72B6;&#x6001;&#x6709;idle&#x548C;dragging&#xFF0C;idle&#x5C31;&#x662F;&#x677E;&#x624B;&#x4E86;&#x5457;</span>
            <span class="hljs-keyword">super</span>.onViewDragStateChanged(state);
        }

        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onViewPositionChanged</span><span class="hljs-params">(View changedView, <span class="hljs-keyword">int</span> left, <span class="hljs-keyword">int</span> top, <span class="hljs-keyword">int</span> dx, <span class="hljs-keyword">int</span> dy)</span> </span>{
            <span class="hljs-comment">///&#x63A7;&#x4EF6;&#x4F4D;&#x7F6E;&#x6539;&#x53D8;&#x4E86;&#xFF0C;&#x5E38;&#x7528;&#x4E8E;&#x914D;&#x5408;&#x8FDB;&#x884C;&#x4E00;&#x4E9B;&#x7279;&#x6548;&#xFF0C;&#x5982;&#x7F29;&#x653E;</span>
            <span class="hljs-keyword">super</span>.onViewPositionChanged(changedView, left, top, dx, dy);
        }

        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onEdgeDragStarted</span><span class="hljs-params">(<span class="hljs-keyword">int</span> edgeFlags, <span class="hljs-keyword">int</span> pointerId)</span> </span>{
            <span class="hljs-keyword">super</span>.onEdgeDragStarted(edgeFlags, pointerId);
            Log.i(<span class="hljs-string">&quot;drag&quot;</span>, <span class="hljs-string">&quot;onEdgeDragStarted--&quot;</span> + edgeFlags);
        }

        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">onEdgeLock</span><span class="hljs-params">(<span class="hljs-keyword">int</span> edgeFlags)</span> </span>{
            <span class="hljs-keyword">boolean</span> res = <span class="hljs-keyword">super</span>.onEdgeLock(edgeFlags);
            Log.i(<span class="hljs-string">&quot;drag&quot;</span>, <span class="hljs-string">&quot;onEdgeLock--&quot;</span> + res);
            <span class="hljs-keyword">return</span> res;
        }

        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onEdgeTouched</span><span class="hljs-params">(<span class="hljs-keyword">int</span> edgeFlags, <span class="hljs-keyword">int</span> pointerId)</span> </span>{
            <span class="hljs-keyword">super</span>.onEdgeTouched(edgeFlags, pointerId);
            Log.i(<span class="hljs-string">&quot;drag&quot;</span>, <span class="hljs-string">&quot;onEdgeTouched--&quot;</span> + edgeFlags);
        }
    };


}
</code></pre>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">FrameLayout</span> <span class="hljs-attr">xmlns:android</span>=<span class="hljs-string">&quot;http://schemas.android.com/apk/res/android&quot;</span>
    <span class="hljs-attr">xmlns:tools</span>=<span class="hljs-string">&quot;http://schemas.android.com/tools&quot;</span>
    <span class="hljs-attr">android:layout_width</span>=<span class="hljs-string">&quot;match_parent&quot;</span>
    <span class="hljs-attr">android:layout_height</span>=<span class="hljs-string">&quot;match_parent&quot;</span>
    <span class="hljs-attr">android:background</span>=<span class="hljs-string">&quot;#ffffff&quot;</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">org.ayo.ui.sample.view_learn.ViewDragHelperDemoView2</span>
        <span class="hljs-attr">android:layout_width</span>=<span class="hljs-string">&quot;match_parent&quot;</span>
        <span class="hljs-attr">android:layout_height</span>=<span class="hljs-string">&quot;match_parent&quot;</span>
        <span class="hljs-attr">android:background</span>=<span class="hljs-string">&quot;#34e6a5&quot;</span>
        &gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">TextView</span>
            <span class="hljs-attr">android:layout_width</span>=<span class="hljs-string">&quot;200dp&quot;</span>
            <span class="hljs-attr">android:layout_height</span>=<span class="hljs-string">&quot;100dp&quot;</span>
            <span class="hljs-attr">android:textColor</span>=<span class="hljs-string">&quot;#ffffff&quot;</span>
            <span class="hljs-attr">android:gravity</span>=<span class="hljs-string">&quot;center&quot;</span>
            <span class="hljs-attr">android:layout_gravity</span>=<span class="hljs-string">&quot;center&quot;</span>
            <span class="hljs-attr">android:text</span>=<span class="hljs-string">&quot;oooo 1 oooo&quot;</span>
            <span class="hljs-attr">android:textSize</span>=<span class="hljs-string">&quot;16sp&quot;</span>
            <span class="hljs-attr">android:background</span>=<span class="hljs-string">&quot;#000000&quot;</span> /&gt;</span>

        <span class="hljs-tag">&lt;<span class="hljs-name">TextView</span>
            <span class="hljs-attr">android:layout_width</span>=<span class="hljs-string">&quot;200dp&quot;</span>
            <span class="hljs-attr">android:layout_height</span>=<span class="hljs-string">&quot;100dp&quot;</span>
            <span class="hljs-attr">android:textColor</span>=<span class="hljs-string">&quot;#ffffff&quot;</span>
            <span class="hljs-attr">android:gravity</span>=<span class="hljs-string">&quot;center&quot;</span>
            <span class="hljs-attr">android:layout_gravity</span>=<span class="hljs-string">&quot;center&quot;</span>
            <span class="hljs-attr">android:text</span>=<span class="hljs-string">&quot;oooo 2 oooo&quot;</span>
            <span class="hljs-attr">android:textSize</span>=<span class="hljs-string">&quot;16sp&quot;</span>
            <span class="hljs-attr">android:background</span>=<span class="hljs-string">&quot;#000000&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">org.ayo.ui.sample.view_learn.ViewDragHelperDemoView2</span>&gt;</span>


<span class="hljs-tag">&lt;/<span class="hljs-name">FrameLayout</span>&gt;</span>
</code></pre>
<ul>
<li>ViewDragHelper&#x63D0;&#x4F9B;&#x7684;&#x529F;&#x80FD;&#x6709;&#xFF1A;<ul>
<li>&#x89E6;&#x6478;&#x4E8B;&#x4EF6;&#x7684;&#x5C01;&#x88C5;</li>
<li>Scroller&#x7684;&#x5C01;&#x88C5;</li>
<li>&#x8FB9;&#x7F18;&#x89E6;&#x6478;&#x76F8;&#x5173;&#x529F;&#x80FD;</li>
</ul>
</li>
</ul>
<h3 id="37-&#x6ED1;&#x52A8;&#x603B;&#x7ED3;&#xFF1A;">3.7 &#x6ED1;&#x52A8;&#x603B;&#x7ED3;&#xFF1A;</h3>
<ul>
<li>&#x6ED1;&#x52A8;&#x603B;&#x7ED3;&#xFF1A;<ul>
<li>&#x6ED1;&#x52A8;View&#x672C;&#x8EAB;&#xFF1A;&#x5E73;&#x79FB;&#x6548;&#x679C;<ul>
<li>layout(left, top, right, bottom)&#xFF1A;&#x6B64;&#x65B9;&#x6CD5;&#x8C03;&#x7528;&#x540E;&#xFF0C;&#x4F1A;&#x91CD;&#x65B0;&#x7ED8;&#x5236;View</li>
<li>MarginLayoutParam&#x63A7;&#x5236;margin&#x6765;&#x5B9E;&#x73B0;&#x6ED1;&#x52A8;</li>
<li>offsetLeftAndRight(dx)&#x548C;offsetTopAndBottom(dy)&#xFF1A;&#x8FD9;&#x4E2A;&#x633A;&#x65B0;&#x9C9C;</li>
<li>translateX&#x548C;tranlateY&#xFF0C;&#x4F46;&#x6CE8;&#x610F;&#x8FD9;&#x4E2A;&#x63A7;&#x5236;&#x7684;&#x662F;View&#x7684;&#x5F71;&#x50CF;</li>
<li>&#x8FD9;&#x91CC;&#x7684;&#x6ED1;&#x52A8;&#x4E00;&#x822C;&#x662F;&#x79FB;&#x52A8;View&#x4F4D;&#x7F6E;&#xFF0C;&#x6216;&#x8005;&#x5E73;&#x79FB;&#x52A8;&#x753B;</li>
</ul>
</li>
<li>&#x6ED1;&#x52A8;View&#x7684;&#x5185;&#x5BB9;&#xFF1A;scroll&#x6548;&#x679C;<ul>
<li>scrollTo&#x548C;scrollBy</li>
<li>&#x5E73;&#x6ED1;&#x79FB;&#x52A8;&#x8981;&#x7528;Scroller&#x6216;Handler&#x6216;&#x5C5E;&#x6027;&#x52A8;&#x753B;&#xFF0C;&#x63A8;&#x8350;Scroller&#xFF0C;&#x5982;&#x679C;&#x662F;&#x5916;&#x90E8;&#x63A7;&#x5236;&#xFF0C;&#x5219;&#x53EA;&#x80FD;&#x662F;Handler&#x6216;&#x5C5E;&#x6027;&#x52A8;&#x753B;</li>
</ul>
</li>
<li>&#x6FC0;&#x6D3B;&#x6ED1;&#x52A8;&#x7684;&#x65B9;&#x5F0F;&#xFF1A;&#x6FC0;&#x6D3B;&#x4E0A;&#x9762;&#x4E24;&#x79CD;&#x6ED1;&#x52A8;&#x65B9;&#x5F0F;<ul>
<li>Touch&#x4E8B;&#x4EF6;&#xFF1A;&#x901A;&#x8FC7;&#x89E6;&#x6478;&#x4E8B;&#x4EF6;&#x6765;&#x5E73;&#x79FB;&#x6216;&#x8005;scroll<ul>
<li>Touch&#x4E8B;&#x4EF6;&#x4F20;&#x9012;</li>
<li>&#x89E3;&#x51B3;&#x51B2;&#x7A81;</li>
</ul>
</li>
<li>&#x76F4;&#x63A5;&#x6ED1;&#x52A8;&#xFF1A;&#x76F4;&#x63A5;&#x8BBE;&#x7F6E;&#x4E2A;&#x5E73;&#x79FB;&#x91CF;&#x6216;scroll&#x91CF;&#xFF0C;&#x7136;&#x540E;&#x5E73;&#x79FB;&#x6216;scroll</li>
</ul>
</li>
<li>&#x6ED1;&#x52A8;&#x7684;&#x6548;&#x679C;&#xFF1A;<ul>
<li>View&#x672C;&#x8EAB;&#x7684;&#x6ED1;&#x52A8;</li>
<li>View&#x5185;&#x5BB9;&#x7684;&#x6ED1;&#x52A8;<ul>
<li>ViewPager&#x6548;&#x679C;&#xFF1A;&#x6700;&#x7EC8;&#x4F1A;&#x505C;&#x5728;&#x67D0;&#x4E00;&#x9875;</li>
<li>ScrollView&#x6548;&#x679C;&#xFF1A;&#x505C;&#x6B62;&#x7684;&#x4F4D;&#x7F6E;&#x4F1A;&#x6839;&#x636E;&#x624B;&#x62AC;&#x8D77;&#x65F6;&#x7684;&#x6ED1;&#x52A8;&#x901F;&#x5EA6;&#x6765;&#x51B3;&#x5B9A;</li>
<li>OverScroll&#x6548;&#x679C;&#xFF1A;&#x6ED1;&#x5230;&#x8FB9;&#x7F18;&#x8FD8;&#x53EF;&#x4EE5;&#x6ED1;&#xFF0C;&#x4E0D;&#x8FC7;&#x4F1A;&#x56DE;&#x5F39;</li>
</ul>
</li>
</ul>
</li>
<li>&#x6ED1;&#x52A8;&#x7684;&#x8F85;&#x52A9;&#x5DE5;&#x5177;&#xFF1A;<ul>
<li>&#x5E73;&#x6ED1;&#x76F8;&#x5173;&#xFF1A;Scroller&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;Intercepter&#x548C;duraion</li>
<li>&#x901F;&#x5EA6;&#x76F8;&#x5173;&#xFF1A;VelocityTracker</li>
<li>&#x7EC8;&#x6781;&#x5927;&#x6740;&#x5668;&#xFF1A;ViewDragHelper</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="4-&#x51E0;&#x4E2A;&#x5E38;&#x7528;&#x7684;&#x6ED1;&#x52A8;&#x63A7;&#x4EF6;&#x7814;&#x7A76;">4 &#x51E0;&#x4E2A;&#x5E38;&#x7528;&#x7684;&#x6ED1;&#x52A8;&#x63A7;&#x4EF6;&#x7814;&#x7A76;</h2>
<ul>
<li>&#x8FD9;&#x91CC;&#x7814;&#x7A76;&#x4E86;&#x6240;&#x6709;&#x5E38;&#x7528;&#x7684;&#x53EF;&#x4EE5;&#x6ED1;&#x52A8;&#x7684;&#x63A7;&#x4EF6;&#xFF0C;&#x7ED9;&#x51FA;&#xFF1A;<ul>
<li>&#x4F7F;&#x7528;&#x65B9;&#x6CD5;</li>
<li>&#x548C;&#x6ED1;&#x52A8;&#x76F8;&#x5173;&#x7684;&#x56DE;&#x8C03;</li>
</ul>
</li>
</ul>
<p>ScrollView</p>
<p>NestedScrollView</p>
<p>ViewPager</p>
<p>ListView</p>
<p>GridView</p>
<p>RecyclerView</p>
<p>DrawerLayout</p>
<p>SwipebackLayout</p>
<p>CodinatorView</p>
<h2 id="4-&#x5B9E;&#x4F8B;1&#xFF1A;-&#x4EFF;scrollview">4 &#x5B9E;&#x4F8B;1&#xFF1A; &#x4EFF;ScrollView</h2>
<p>FakeScrollView</p>
<h2 id="5-&#x5B9E;&#x4F8B;2&#xFF1A;-&#x4EFF;viewpager">5 &#x5B9E;&#x4F8B;2&#xFF1A; &#x4EFF;ViewPager</h2>
<p>FakeHorizontalScrollView</p>
<h2 id="6-&#x5B9E;&#x4F8B;3&#xFF1A;stickylayout">6 &#x5B9E;&#x4F8B;3&#xFF1A;StickyLayout</h2>
<p>&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x4E00;&#x4E2A;ListView&#x548C;&#x4E00;&#x4E2A;&#x4EFB;&#x610F;&#x7684;headerView&#xFF0C;&#x5728;&#x5408;&#x9002;&#x65F6;&#x673A;&#x4F1A;&#x63A5;&#x7BA1;ListView&#x7684;&#x6ED1;&#x52A8;&#x6743;&#x9650;</p>
<h2 id="7-&#x5B9E;&#x4F8B;4&#xFF1A;-pinnedheaderexpandablelistview">7 &#x5B9E;&#x4F8B;4&#xFF1A; PinnedHeaderExpandableListView</h2>
<p>Pinned&#x6548;&#x679C;&#x7684;ExpandableListView&#xFF0C;&#x76F4;&#x63A5;&#x7EE7;&#x627F;ExpandableListView</p>
<h2 id="&#x6700;&#x540E;&#xFF1A;&#x624B;&#x52BF;">&#x6700;&#x540E;&#xFF1A;&#x624B;&#x52BF;</h2>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="status-ui.html" class="navigation navigation-prev " aria-label="Previous page: StatusUI系列库">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="layout.html" class="navigation navigation-next " aria-label="Next page: Layout">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"滑动","level":"1.8","depth":1,"next":{"title":"Layout","level":"1.9","depth":1,"path":"layout.md","ref":"layout.md","articles":[]},"previous":{"title":"StatusUI系列库","level":"1.7","depth":1,"path":"status-ui.md","ref":"status-ui.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"touch-scroll.md","mtime":"2017-04-09T16:58:40.227Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-04-09T17:03:25.521Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

